//
//  JimDelightHashTable3.h
//  CollectionTest
//
//  Created by Dusan Vujosevic on 2013-10-27.
//  Copyright (c) 2013 Suavetech. All rights reserved.
//

#ifndef __CollectionTest__JimDelightHashTable3__
#define __CollectionTest__JimDelightHashTable3__

#include "CollectionBase.h"
#include <set>

template <typename Tkey>
class STBucket3
{
public:
	STBucket3(): _elems(NULL), _elemsAlloc(0), _elemsCount(0) {}
	
	void AddElem(Tkey& elem);
	bool ContainsElem(const Tkey& elem) const;
	
private:
	Tkey* _elems;
	size_t _elemsAlloc;
	size_t _elemsCount;
};

class JimDelightHashTable3: public CollectionBase
{
public:
	JimDelightHashTable3(size_t elementCountHint);
	virtual ~JimDelightHashTable3();

	virtual const char* name() const { return "JimDelightHashTable3"; }

	virtual void reset();
	
	// Load the collection, mandatory, timed
	virtual void loadElements(const void* randBytes, size_t elemCount);
	
	// Random search, mandatory, timed
	virtual bool findElement(elemType elem);

private:
	size_t hash(const elemType& elem) const { return (size_t)elem & _mask; }
	
	elemType _mask;
	size_t _tableSize;
	STBucket3<elemType>* _table;
};

#endif /* defined(__CollectionTest__JimDelightHashTable3__) */
